package com.gec.service;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.print.attribute.HashAttributeSet;

import com.gec.dao.ProductDao;
import com.gec.entity.CartItem;
import com.gec.entity.Product;

public class ProductService {
	ProductDao productDao= new ProductDao();
	public Map<String,List<Product>> getProductByHoutAndPdate(){
		try {
			List<Product> isHot=productDao.findProductByIsHot();
			List<Product> date=productDao.findProductByIsHot();
			Map<String,List<Product>> map = new HashMap();
			map.put("isHot",isHot);
			map.put("date",isHot);
			return map;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
	
	public Product getProductById(int pid) {
		
			Product product;
			try {
				product = productDao.findProductById(pid);
				return product;
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return null;

	}
	public CartItem createCartItem(int pid, int buyNum) {
		CartItem cartItem = new CartItem();
		cartItem.setBuyNum(buyNum);
		Product product=this.getProductById(pid);
		cartItem.setProduct(product);
		return cartItem;
	}
}
